﻿// baseInterface should be the base class of the SWF.
package com.cf.core.view{
	import com.cf.core.Utils.*;
	import com.cf.core.view.MyScene;
	import com.cf.core.events.GameEvent;
	import com.cf.core.events.LoadEvent;
	import flash.events.MouseEvent;
	public class gameInterface extends baseInterface{
		/*****************
		@ author Canis
		@ function to control the interface, soundLoop, soundFX, task, scene everything
		//****************/
		// Built-in Sound channel, Scene Control, preloadFunction
		// GameStatus control , start, pause, resume, stop
		private var G_scene:cache;
		public function get SCENE():Function {return this.G_scene.address}
		public function gameInterface():void{
			addEventListener(LoadEvent.ONLOAD, handleStatus);
			G_scene=new cache();
			super();
		}//fn
		
		private function handleStatus(e:LoadEvent):void{
			trace("gameInterface : ONLOAD");
		}//fn
		
		public function addScene(_name:String, _class:*):void{
			this.G_scene.address(_name,_class);
			if ( this.G_scene.address(_name) is MyScene){
				trace("gameInterface : import class ["+_name+"] Match");
				this.G_scene.address(_name).sync_var(SYNC_VAR);
				this.G_scene.address(_name).addEventListener(GameEvent.START, START);
				this.G_scene.address(_name).addEventListener(GameEvent.PAUSE, PAUSE);
				this.G_scene.address(_name).addEventListener(GameEvent.RESUME, RESUME);
				this.G_scene.address(_name).addEventListener(GameEvent.FAIL, FAIL);
				this.G_scene.address(_name).addEventListener(GameEvent.OTHER, OTHER);
			}else trace("gameInterface : import class ["+_name+"] unknow");
		}
		public function playScene(_name:String, _layer:int=-1):void {
			trace("gameInterface>addScene : " + G_scene.address(_name));
			if ( _layer != -1 ) {
				this.addChildAt( G_scene.address(_name), _layer );
			}else this.addChild( G_scene.address(_name) );
		}
		public function delScene(_name:String):void{
			this.G_scene.address(_name).removeEventListener(GameEvent.START, START);
			this.G_scene.address(_name).removeEventListener(GameEvent.PAUSE, PAUSE);
			this.G_scene.address(_name).removeEventListener(GameEvent.RESUME, RESUME);
			this.G_scene.address(_name).removeEventListener(GameEvent.FAIL, FAIL);
			this.G_scene.address(_name).removeEventListener(GameEvent.OTHER, OTHER);
			this.removeChild( this.G_scene.address(_name) );
			this.G_scene.RELEASE(_name);
			trace("gameInterface>delScene : " + _name);
		}//fn
		
		//
		// EVENT
		//
		public function START(e:*=null):void{
			trace("gameInterface : GameStart");
			dispatchEvent(new GameEvent(GameEvent.START) );
		}//fn
		public function PAUSE(e:*=null):void{
			trace("gameInterface : GamePause");
			dispatchEvent(new GameEvent(GameEvent.PAUSE));
		}//fn
		public function RESUME(e:*=null):void{
			trace("gameInterface : GameResume");
			dispatchEvent(new GameEvent(GameEvent.RESUME));
		}//fn
		public function FAIL(e:*=null):void{
			trace("gameInterface : GameFAIL");
			dispatchEvent(new GameEvent(GameEvent.FAIL));
		}//fn
		public function OTHER(e:*=null):void{
			trace("gameInterface : GameOther");
			// dispatchEvent(new GameEvent(GameEvent.OTHER, { VAR:"init" } ));
			dispatchEvent(new GameEvent(GameEvent.OTHER, e.data));
		}//fn
	}//class
}//package